package dict

import (
	"gitee.com/alex_li/amazon-rpt/internal/db"
	"gitee.com/alex_li/amazon-rpt/internal/tool"
)

var RptColumns = make(map[string][]db.Column)

func _genColumnKey(reportType ReportType, product AdProductType, unit RptTimeUnit) string {
	return product.Name + unit.Name + string(reportType)
}

func _addRptColumn(reportType ReportType, product AdProductType, column ...db.Column) {
	var key string

	key = _genColumnKey(reportType, product, Summary)

	var tmp []db.Column
	tmp = column
	tmp = append(tmp, db.Column{
		Field: "startDate",
		Type:  db.String,
	}, db.Column{
		Field: "endDate",
		Type:  db.String,
	})
	_saveColumns(key, tmp...)

	key = _genColumnKey(reportType, product, Daily)
	tmp = column
	tmp = append(tmp, db.Column{
		Field: "date",
		Type:  db.String,
	})
	_saveColumns(key, tmp...)
}

func _saveColumns(key string, columns ...db.Column) {
	var dest []db.Column
	for _, column := range columns {
		dest = append(dest, db.Column{
			ColumnName: tool.CamelToSnake(column.Field),
			Field:      column.Field,
			Type:       column.Type,
		})
	}
	RptColumns[key] = dest
}

func GetRptColumns(reportType ReportType, product AdProductType, unit RptTimeUnit) []db.Column {
	var key = _genColumnKey(reportType, product, unit)
	return RptColumns[key]
}

func init() {

}
